# 创建蓝图
from flask import Blueprint
import pymysql
from DBUtils.pooled_db import PooledDB

bindex = Blueprint("index", __name__)

# 连接MySQL数据库
CONN = pymysql.connect(
    host="localhost", port=3306, user="root", passwd="123456", db="flasktest"
)


# 查询数据库全部数据
def fetchall(sql):
    cursor = CONN.cursor()
    cursor.execute(sql)
    result = cursor.fetchall()
    cursor.close()
    return result


@bindex.route("/f1")
def f1():
    # 查询数据库所有数据
    result = fetchall("select * from user")

    return "index f1"


@bindex.route("/f2")
def f2():
    return "index f2"
